﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.NodeFactory;
using System.Web.SessionState;
using umbraco.BusinessLogic.Actions;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.property;
using umbraco.interfaces;

namespace ExtendedWorkFlow.Pages
{

    public partial class Differences : umbraco.BasePages.UmbracoEnsuredPage
    {

        #region Variables

        int _Id = 1050;

        #endregion

        #region Private Classes

        public class PropertyDifference
        {

            #region Variables

            umbraco.cms.businesslogic.property.Property _Property;
            string _Published;
            string _Design;

            #endregion

            #region Constructor

            public PropertyDifference(umbraco.cms.businesslogic.property.Property Property, string Published, string Design)
            {
                this._Property = Property;
                this._Design = Design;
                this._Published = Published;
            }

            #endregion

            #region Properties

            public umbraco.cms.businesslogic.property.Property Property { get { return this._Property; } }
            public string Published { get { return this._Published; } }
            public string Design { get { return this._Design; } }

            #endregion

        }

        #endregion

        #region Page Loading

        protected void Page_Load(object sender, EventArgs e)
        {
            // Get the id from the querystring
            this._Id = Functions.ToInt(this.Page.Request.QueryString["id"]);

            List<PropertyDifference> colPropertyDifference = new List<PropertyDifference>();
            Document objDocument = new Document(this._Id);
            Node objNode = new Node(this._Id);

            // Create collection of all properties, published in node xml and document database
            foreach (umbraco.cms.businesslogic.property.Property objProperty in objDocument.GenericProperties)
            {
                colPropertyDifference.Add(new PropertyDifference(
                    objProperty,
                    (objNode.Properties[objProperty.PropertyType.Alias] != null ? objNode.Properties[objProperty.PropertyType.Alias].Value.ToString() : string.Empty),
                    objProperty.Value.ToString()));
            }

            // Databind
            this.rptProperties.DataSource = colPropertyDifference;
            this.rptProperties.DataBind();
        }

        #endregion

    }

}